// #include "../../common/detail.hpp"
// using namespace rpc;
// int main()
// {
//     for(int i = 0;i<10;i++)
//     {
//        std::cout<<UUID::uuid()<<std::endl;
//     }

// }

// #include <iostream>

// using namespace std;

// class A
// {
// public:
// 	 virtual void hh(int a = 0)=0;
// };

// class B:public A
// {
// public:
// 	 void hh(int a = 2)
//     {
//         std::cout<<"b:"<<std::endl;
//     }
// };

// class C :public B
// {
// public:
// 	void hh(int a = 3)
// 	{
// 		std::cout << a << std::endl;
// 	}
// };

// int main()
// {
// 	B* a = new C;
// 	a->hh();
// 	return 0;
// }

#include "../../common/message.hpp"
#include "../../common/abstract.hpp"

int main()
{
    // rpc::RpcRequest::ptr rrp = rpc::MessageFactory::create<rpc::RpcRequest>();
    // Json::Value param;
    // param["num1"] = 11;
    // param["num2"] = 22;
    // rrp->setMethod("Add");
    // rrp->setParams(param);
    // std::string str = rrp->serialize();
    // std::cout<<str<<std::endl;
    // rpc::BaseMessage::ptr bmp = rpc::MessageFactory::create(rpc::MType::REQ_RPC);
    // bool ret = bmp->unserialize(str);//反序列化
    // if(ret == false) return -1;
    // ret = bmp->check();
    // if(ret == false) return -1;
    // rpc::RpcRequest::ptr rrp2 = std::dynamic_pointer_cast<rpc::RpcRequest>(bmp);
    // std::cout<<rrp2->method()<<std::endl;
    // std::cout<<rrp2->params()["num1"].asInt()<<std::endl;
    // std::cout<<rrp2->params()["num2"].asInt()<<std::endl;

    // rpc::TopicRequest::ptr trp = rpc::MessageFactory::create<rpc::TopicRequest>();
    // trp->setTopicKey("news");
    // trp->setOptype(rpc::TopicOptype::TOPIC_PUBLISH);
    // //内容
    // trp->setTopicMsg("hello world");
    // std::string str = trp->serialize();
    // std::cout<<str<<std::endl;
    // rpc::BaseMessage::ptr bmp = rpc::MessageFactory::create(rpc::MType::REQ_TOPIC);
    // bool ret = bmp->unserialize(str);
    // if(ret == false) return -1;
    // ret = bmp->check();
    // if(ret == false) return -1;
    // rpc::TopicRequest::ptr trp2 = std::dynamic_pointer_cast<rpc::TopicRequest>(bmp);
    // std::cout<<trp2->topicKey()<<std::endl;
    // std::cout<<(int)trp2->optype()<<std::endl;
    // std::cout<<trp2->topicMsg()<<std::endl;

    // rpc::ServiceRequest::ptr srp = rpc::MessageFactory::create<rpc::ServiceRequest>();
    // srp->setMethod("Add");
    // // srp->setOptype(rpc::ServiceOptype::SERVICE_DISCOVERY);
    // srp->setOptype(rpc::ServiceOptype::SERVICE_REGISTRY);
    // srp->setHost(rpc::Address("127.0.0.1",8888));
    // std::string str = srp->serialize();
    // std::cout<<str<<std::endl;
    // rpc::BaseMessage::ptr bmp = rpc::MessageFactory::create(rpc::MType::REQ_SERVICE);
    // bool ret = bmp->unserialize(str);
    // if(ret == false) return -1;
    // ret = bmp->check();
    // if(ret == false) return -1;
    // rpc::ServiceRequest::ptr srp2 = std::dynamic_pointer_cast<rpc::ServiceRequest>(bmp);
    // std::cout<<srp2->method()<<std::endl;
    // std::cout<<(int)srp2->optype()<<std::endl;
    // std::cout<<srp2->host().first<<std::endl;
    // std::cout<<srp2->host().second<<std::endl;

    // rpc::RpcResponse::ptr srp = rpc::MessageFactory::create<rpc::RpcResponse>();
    // srp->setRCode(rpc::RCode::RCODE_OK);
    // Json::Value val;
    // val = 33;
    // srp->setResult(val);
    // std::string str = srp->serialize();
    // std::cout<<str<<std::endl;
    // rpc::BaseMessage::ptr bmp = rpc::MessageFactory::create(rpc::MType::RSP_RPC);
    // bool ret = bmp->unserialize(str);
    // if(ret == false) return -1;
    // ret = bmp->check();
    // if(ret == false) return -1;
    // rpc::RpcResponse::ptr srp2 = std::dynamic_pointer_cast<rpc::RpcResponse>(bmp);
    // std::cout<<(int)srp2->rcode()<<std::endl;
    // std::cout<<srp2->result().asInt()<<std::endl;

    // rpc::TopicResponse::ptr srp = rpc::MessageFactory::create<rpc::TopicResponse>();
    // srp->setRCode(rpc::RCode::RCODE_OK);
    // std::string str = srp->serialize();
    // std::cout << str << std::endl;
    // rpc::BaseMessage::ptr bmp = rpc::MessageFactory::create(rpc::MType::RSP_TOPIC);
    // bool ret = bmp->unserialize(str);
    // if (ret == false)
    //     return -1;
    // ret = bmp->check();
    // if (ret == false)
    //     return -1;
    // rpc::TopicResponse::ptr srp2 = std::dynamic_pointer_cast<rpc::TopicResponse>(bmp);
    // std::cout << (int)srp2->rcode() << std::endl;

    rpc::ServiceResponse::ptr srp = rpc::MessageFactory::create<rpc::ServiceResponse>();
    srp->setRCode(rpc::RCode::RCODE_OK);
    srp->setMethod("Add");
    srp->setOptype(rpc::ServiceOptype::SERVICE_DISCOVERY);
    std::vector<rpc::Address> addrs;
    addrs.push_back(rpc::Address("127.0.0.1",8888));
    addrs.push_back(rpc::Address("127.0.0.1",9090));
    srp->setHost(addrs);
    std::string str = srp->serialize();
    std::cout << str << std::endl;
    rpc::BaseMessage::ptr bmp = rpc::MessageFactory::create(rpc::MType::RSP_SERVICE);
    bool ret = bmp->unserialize(str);
    if (ret == false)
        return -1;
    ret = bmp->check();
    if (ret == false)
        return -1;
    rpc::ServiceResponse::ptr srp2 = std::dynamic_pointer_cast<rpc::ServiceResponse>(bmp);
    std::cout << (int)srp2->rcode() << std::endl;
    std::cout<<(int)srp2->optype()<<std::endl;
    std::cout<<srp2->method()<<std::endl;
    std::vector<rpc::Address> addrs1 = srp2->hosts();
    for(auto & addr:addrs1)
    {
        std::cout<<addr.first<<":"<<addr.second<<std::endl;
    }

    return 0;
}